package com.longkey.workflow.client.view
{
	import flash.display.DisplayObject;
	import flash.events.ContextMenuEvent;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	import flash.utils.getQualifiedClassName;
	
	import mx.controls.Alert;
	import mx.controls.treeClasses.TreeItemRenderer;
	import mx.core.IUITextField;
	import mx.core.UIFTETextField;
	import mx.core.UITextField;
	import mx.core.mx_internal;
	
	use namespace mx_internal;
	
	public class NavigatorItemRender extends TreeItemRenderer
	{
		public function NavigatorItemRender()
		{
			super();
//			this.contextMenu = this.createContextMenu();
		}
		
		override mx_internal function createLabel(childIndex:int):void
		{
			// TODO Auto Generated method stub
//			super.mx_internal::createLabel(childIndex);
//			label.border = true;
			if (!label)
			{
				label = IUITextField(createInFontContext(UITextField));
				label.styleName = this;
//				label.border = true;
//				UITextField(label).contextMenu = this.createContextMenu();
//				var txt:UITextField = this.label as UITextField;
//				txt.contextMenu = this.createContextMenu();
//				txt.backgroundColor = 0x00FF00;
				
				if (childIndex == -1)
					addChild(DisplayObject(label));
				else 
					addChildAt(DisplayObject(label), childIndex);
			}
		}
		
		private function createContextMenu():ContextMenu{
			
			var ctx:ContextMenu = new ContextMenu();
			ctx.hideBuiltInItems();
			var menu:ContextMenuItem = new ContextMenuItem("新增目录11");
			menu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, fun);
			ctx.customItems.push(menu);
			
			menu = new ContextMenuItem("新建流程22");
			menu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, fun);
			ctx.customItems.push(menu);
			
			menu = new ContextMenuItem("重命名33");
			menu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, fun);
			ctx.customItems.push(menu);
			
			menu = new ContextMenuItem("删除44");
			menu.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, fun);
			ctx.customItems.push(menu);
			
//			ctx.addEventListener(ContextMenuEvent.MENU_SELECT, fun);
			
			return ctx;
		}
		
		public function fun(event:ContextMenuEvent):void{
			Alert.show("test");
		}
	}
}